--抹蠲圭音
local mojuanguiyin = fk.CreateSkill {
    name = "mcdh_mojuanguiyin",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

mojuanguiyin:addEffect(fk.CardUseFinished,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not player:hasSkill(self) or player:usedSkillTimes(self.name, Player.HistoryTurn) > 0 then return false end
        return data.from == room.current.id and data.from:getHandcardNum() > player:getHandcardNum()
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local typeMap = {
            ["basic"]  = "基本",
            ["trick"]  = "锦囊",
            ["equip"]  = "装备",
            ["notype"] = "其它类型"
        }
        return room:askForSkillInvoke(
                player,
                self.name,
                nil,
                "#mcdh_mojuanguiyin-invoke:" .. room.current.id .. "::" .. typeMap[data.card:getTypeString()]
        )
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@@mcdh_mojuanguiyin_" .. data.card:getTypeString() .. "-turn", data.from)
        data.from:drawCards(1, self.name)
    end,
})

mojuanguiyin:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        return player:getMark("@@mcdh_mojuanguiyin_" .. data.card:getTypeString() .. "-turn") == data.from and not data.from:isNude()
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = data.from
        local cids = room:askForCard(
                to,
                1, 1,
                true,
                self.name,
                false,
                ".",
                "#mcdh_mojuanguiyin_trigger-invoke:" .. player.id
        )
        if #cids > 0 then
            room:obtainCard(
                    player,
                    cids,
                    false,
                    fk.ReasonGive,
                    data.from,
                    self.name
            )
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_mojuanguiyin"] = "智辅",
    [":mcdh_mojuanguiyin"] = "『抹蠲(juān)圭音』<br>每回合限一次，手牌数大于你的角色在其回合内使用牌后，你可以令其摸一张牌，其本回合再使用与此牌类型相同的牌时，其交给你一张牌。",
    ["#mcdh_mojuanguiyin-invoke"] = "抹蠲圭音：令 %src 摸一张牌。本回合其再使用 %arg 牌时，须交给你一张牌",
    ["#mcdh_mojuanguiyin_trigger-invoke"] = "抹蠲圭音：交给 %src 一张牌",
    ["@@mcdh_mojuanguiyin_basic-turn"] = "抹蠲圭音-基",
    ["@@mcdh_mojuanguiyin_trick-turn"] = "抹蠲圭音-锦",
    ["@@mcdh_mojuanguiyin_equip-turn"] = "抹蠲圭音-装",
    ["@@mcdh_mojuanguiyin_notype-turn"] = "抹蠲圭音-？",
}

return mojuanguiyin